package com.wt.ecommerce.stream.custom;

import com.alibaba.fastjson.JSON;
import com.wt.ecommerce.vo.CommonMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Payload;

/**
 * <h1>使用自定义的输入信道实现消息的接收</h1>
 */
@Slf4j
@EnableBinding(CustomSink.class)
public class CustomReceiveService {

    /**
     * 使用自定义的输入信道接收消息
     */
    @StreamListener(CustomSink.INPUT)
    public void receiveMessage(@Payload Object payload) {

        log.info("in CustomReceiveService consume message start");
        CommonMessage commonMessage = JSON.parseObject(payload.toString(), CommonMessage.class);
        log.info("in CustomReceiveService consume message success: [{}]",
                JSON.toJSONString(commonMessage));
    }
}
